<div class="modal fade bs-modal-md" id="modelContent">
	<div class="modal-dialog modal-md" style="width: 960px;">
		<div class="modal-content"></div>
	</div>
</div>

<div class="portlet box green form">
    <div class="portlet-title">
		<div class="caption"><i class="fa fa-cogs"></i>订单 &gt; 订单管理 &gt; 订单编辑</div>
		<div class="tools"><a href="javascript:;" class="collapse" data-original-title="" title=""> </a></div>
    </div>
    <div class="portlet-body">
    	<div class="tabbable-line ">
			<ul class="nav nav-tabs ">
				<li class="active"><a href="/order/edit?orderId=$!item.id" class="ajaxify" id="orderInfoLink">订单信息</a></li>
				<li><a href="/orderItem/list?orderId=$!item.id" class="ajaxify">订单货品</a></li>
				<li><a href="/orderReceipt/orderBills?orderId=$!item.id" class="ajaxify">单据信息</a></li>
				<li><a href="/orderLog/orderLogs?id=$!item.id" class="ajaxify">订单日志</a></li>
			</ul>
		</div>
		<div class="portlet-body">
			#if($!item.orderState=='INIT_STATE' || $!item.orderState=='WAIT_CONFIRM_SALES')
		   	 <a href="javascript:;" class="btn btn-circle default" onclick="makeSure('$!item.id');" >确认</a>
		   	 #end
		   	 #if($!item.orderState=='WAIT_BUYER_PAY')
		   	 <a href="javascript:;" class="btn btn-circle default" onclick="payOrderByCredits('$!item.id');">付款</a>
		   	 #end
		   	 #if($!item.orderState=='WAIT_DELIVERY')
		   	 <a href="#modelContent" thref="/sendGoods/add?id=$!item.id" class="btn btn-circle default ajax-model-get" data-toggle="modal">发货</a>
		   	 #end
		   	 #if($!item.orderState=='WAIT_REVICE')
		   	 <a href="javascript:;" class="btn btn-circle default" onclick="finishOrder('$!item.id');">完成</a>
		   	 #end
		   	 #if($!item.orderState=='INIT_STATE' || $!item.orderState=='WAIT_BUYER_PAY' || $!item.orderState=='WAIT_DELIVERY')
		   	 <a href="javascript:;" class="btn btn-circle default" onclick="cancelOrder('$!item.id');">取消</a>
		   	 #end
		   	 #if($!item.orderState=='INIT_STATE' || $!item.orderState=='WAIT_BUYER_PAY')
		   	 <a href="#modelContent" thref="/order/changePrice?id=$!item.id" class="btn btn-circle default ajax-model-get" data-toggle="modal">调价</a>
		   	 #end
		   	 <a href="#modelContent" thref="/orderInvoice/invoice?id=$!item.id" class="btn btn-circle default ajax-model-get" data-toggle="modal">开票</a>
		   	 #if($!item.orderState =='TRADE_FINISHED' && $!item.canService)
		   	 <a href="#modelContent" thref="/afterMarketOrder/makeApply?id=$!item.id" class="btn btn-circle default ajax-model-get" data-toggle="modal">申请售后</a>
		   	 #end
		   	 #if($!item.orderState =='WAIT_REVICE')
		   	 <a href="#modelContent" thref="/sendGoods/edit?orderId=$!item.id" class="btn btn-circle default ajax-model-get" data-toggle="modal">修改发货</a>
		   	 #end
		</div>
		
    	<div class="dataTables_wrapper no-footer">
			<div class="table-scrollable">
				<h3>基本信息</h3>
			      <table class="table table-striped table-bordered table-hover center">
			      	<tbody>
				      	<tr>
				      		<td>订单号</td><td>$!item.id</td>
				      		<td>订单状态</td><td>$!item.orderState.name</td>
				      		<td>订单金额</td><td>$!item.total</td>
				      		<td>配送方式</td><td>$!item.tranType.name</td>
				      	</tr>
				      	<tr>
				      		<td>会员姓名</td><td>
 								$!user.realname
				      		</td>
				      		<td>所属企业</td><td>
				      			#if($!company.name)
				      				$!company.name <a class="btn-sm ajaxify" href="/details/list?id=$!company.id">($!company.id)</a>
				      			#else
				      				无
				      			#end
				      		</td>
				      		<td>购买会员</td><td>$!user.nickname <a href="userInfo/detail?id=$!user.id" class="ajaxify">($!user.id)</a></td>
				      		<td>赠送会员积分</td><td>$!score</td>
				      		
				      	</tr>
				      	<tr>
				      		<td>付款类型</td><td>$!item.settleWay.name</td>
				      		<td>总物流重量</td><td>$!item.totalWeight kg</td>
				      		<td>总物流体积</td><td>$!item.totalVolume m³</td>
				      		<td>货品总件数</td><td>$!item.totalNum</td>
				      	</tr>
				      	<tr>
				      		<td>会员来源</td><td>$!user.MemberSource</td>
				      		<td>下单时间</td><td>$!item.createDate</td>
				      		<td>付款时间</td><td>$!item.payDate</td>
				      	</tr>
			      	</tbody>
			      </table>
			</div>
			
			<div class="table-scrollable">
				<h3>订单金额计算/支付详情</h3>
			      <table class="table table-striped table-bordered table-hover">
			      	<tbody>
				      	<tr align="center">
				      		<td colspan="8">$!item.productFee（货品总额）+ <input type="text" style="width: 75px;" value="$!item.deliverFee" readOnly/>（运费）- $!item.promotionsReduction（促销减免）- $!item.couponReduction（优惠券抵扣） - <input type="text" style="width: 75px;" value="$!item.otherReduction" readOnly />（人工改价）= $!item.total 元（订单金额）</td>
				      	</tr>
				      	<tr>
				      		<td>信用支付</td><td>#if($!item.settleWay=='CREDIT')$!item.total #else 0 #end </td>
				      		<td>在线支付</td><td>#if($!item.settleWay=='WECHAT' || $!item.settleWay=='ALIPAY')$!item.total #else 0 #end </td>
				      		<td>企业信用余额</td><td>$!company.creditOver</td>
				      		<td>支付时间</td><td>$!item.payDate</td>
				      	</tr>
			      	</tbody>
			      </table>
			</div>
			
			<form action="/order/saveNote" class="form-horizontal" method="post" id="orderEditForm" >
			<div class="table-scrollable">
				<h3>收货信息</h3>
			     
			      <table class="table table-striped table-bordered table-hover">
			      	<tbody>
				      	<tr>
				      		<td>收货人</td><td ">$!item.shippingInfoModel.receiver</td>
				      		<td>联系电话</td><td>$!item.shippingInfoModel.phone</td>
				      		<td>期望收货日期</td><td id="receiveDate">$!item.RequirementDate</td>
				      		<td>预计收货日期</td>
				      		<td nowrap >
					      		#if($item.orderState == 'INIT_STATE')
					      		<div class="form-group">
						      		<input type="text" class="form-control common-date-datepicker" id="dateTime" name="ConsignmentDate" value="$!item.ConsignmentDate" readOnly required style="width: 145px;display: inline;"><span style="color: red;"></span>
									<i class="fa fa-calendar" style="display: inline;"></i>
								</div>
					      		#else
					      			$!item.ConsignmentDate
								#end
				      		</td>
				      	</tr>
				      	<tr>
				      		<td>收货地区</td>
					      		<td>
						      		$!item.shippingInfoModel.province 
						      		$!item.shippingInfoModel.city 
						      		$!item.shippingInfoModel.county
					      		</td>
				      		<td>详细地址</td><td colspan="5">$!item.shippingInfoModel.address</td>
				      	</tr>
			      	</tbody>
			      </table>
			</div>
			
			
			<div class="table-scrollable">
				<h3>发票信息</h3>
			      <table class="table table-striped table-bordered table-hover">
			      	<tbody>
				      	<tr>
				      		<td>发票类型</td><td>$!invoice.invoiceType.name</td>
				      		<td>发票抬头</td><td>$!invoice.title</td>
				      		<td>发票内容</td><td>$!invoice.content</td>
				      	</tr>
				      	<tr>
				      		<td>统一社会信用代码</td><td>$!invoice.taxpayerNumber</td>
				      		<td>开户银行</td><td>$!invoice.depositBank</td>
				      		<td>开户银行账号</td><td>$!invoice.accountBank</td>
				      	</tr>
				      	<tr>
				      		<td>营业电话</td><td>$!invoice.companyPhone</td>
				      		<td>营业地址</td><td>$!invoice.companyAddress</td>
				      		<td>&nbsp;</td><td></td>
				      	</tr>
			      	</tbody>
			      </table>
			</div>
			<div class="table-scrollable">
				<h3>客户留言 / 订单备注 </h3>
			      <table class="table table-striped table-bordered table-hover">
			      	<tbody>
				      	<tr>
				      		<td>
				      				<div class="form-group">
						      			<textarea rows="5" name="leaveMsg" style="width: 100%" readOnly>$!item.leaveMsg</textarea>
					      			</div>
				      		</td>
				      		
				      		<td>
				      		
				      			#if($!item.orderState == 'INIT_STATE')
				      				<div class="form-group">
						      			<textarea rows="5" name="note" style="width: 100%" >$!item.note</textarea>
					      			</div>
				      			#else 
					      			$!item.note
				      			#end
				      			<input type="hidden" name="orderState" id="orderState" value="$!item.orderState">
				      			<input type="hidden" name="id" value="$!item.id">
				      			<input type="hidden" name="userId" value="$!item.userId"/>
				      		</td>
				      	</tr>
				      	<tr>
				      		<td align="center">
				      			#if($!item.orderState == 'INIT_STATE')
				      			<a class="btn green ajax-post" href="javascript:;" thref="/order/edit?orderId=$!item.id" id='btnSaveOrder'> 
									<i class="fa fa-edit"></i>保存
								</a>
								#end
								&nbsp;&nbsp;
								<a class="btn green btn-sm ajaxify" href="/order/list?orderState=$!item.orderState"> 
									<i class="fa fa-close"></i>关闭
								</a>
				      		</td>
				      	</tr>
			      	</tbody>
			      </table>
			      
			</div>
			</form>
		</div>
    </div>
</div>
<script src="/assets/scripts/views-date.js" type="text/javascript"></script>
<script type="text/javascript">

ComponentsSelect2.initWithSearch()
MyTouchSpin.init()

/**
 * 确认订单
 */
function makeSure(orderId) {
	$('#orderState').val('WAIT_BUYER_PAY') ;
	$('#orderEditForm').attr('action','/order/makeSure');
	$('#btnSaveOrder').click() ;
}

/**
 * 通过信用支付
 */
 function payOrderByCredits(orderId) {
	 $.post('/order/payOrderByCredits',{'id':orderId},function(data){
		var res = JSON.parse(data);
		if(res.code == 0) {
			toastr.success(res.msg);
			$('#orderInfoLink').click();
		} else {
			toastr.warning(res.msg);
		}
	});
}

/**
 * 取消订单
 */
 function cancelOrder(orderId) {
	 $.get('/order/cancelOrder',{'id':orderId},function(data){
		var res = JSON.parse(data);
		if(res.code == 0) {
			toastr.success(res.msg);
			$('#orderInfoLink').click();
		} else {
			toastr.warning(res.msg);
		}
	});
}

 /**
  * 完成订单
  */
  function finishOrder(orderId) {
 	 $.get('/order/finishOrder',{'id':orderId},function(data){
 		var res = JSON.parse(data);
 		if(res.code == 0) {
 			toastr.success(res.msg);
 			$('#orderInfoLink').click();
 		} else {
 			
 			toastr.warning(res.msg);
 		}
 	});
 }
 /**
 *驗證時間
 */
  var submitbottom=$("#dateTime").change(function(){
	
	  $(this).next("span").addClass("help-block").html("");
	  
	  var flag=false;
	 var dateObj = new Date().getTime();
	 
	  var endtime=new Date($(this).val()).getTime();
	  
	  if(endtime!=null||endtime==""){
		  if(endtime<dateObj){		
				 if($(this).next("span").val()==null||$(this).next("span").val()==""){
				       $(this).next("span").addClass("help-block").html("预计收货日期大于现在日期");
				 }
		 }else{
			
			 flag=true;
		  }
		    
	  }
	 return flag;
 });

 
</script>

